package com.sudichina.sudichina.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sudichina.sudichina.R;

import static com.sudichina.sudichina.R.style.dialog;

/**
 * Name: DialogFrameAnimUtils
 * Action:
 * Author: liuan
 * creatTime:2017-03-18 14:50
 */

public class DialogFrameAnimUtils {



    public static void startSucessAnim(Context context, Activity activity, String Mymsg) {
        View view = View.inflate(context, R.layout.imageview_single, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity, dialog);
        ImageView iv = (ImageView) view.findViewById(R.id.iv_frameanim);
        TextView tv = (TextView) view.findViewById(R.id.tv_commit);
        tv.setText(Mymsg);

       final AlertDialog Mydialog = builder.create();


        Mydialog.show();
        Mydialog.setContentView(view);

        AnimationDrawable animationDrawable = (AnimationDrawable) iv.getDrawable();
        animationDrawable.start();
//        while (!animationDrawable.isRunning()) {
//            dialog.dismiss();
//        }
        int duration = 0;
        for(int i=0;i<animationDrawable.getNumberOfFrames();i++){
            duration += animationDrawable.getDuration(i);

        }

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                //此处调用第二个动画播放方法
                Mydialog.dismiss();


            }
        }, duration+100);

    }
}
